package org.honeyweb.gsoc.services.impl;

import java.util.ArrayList;
import java.util.Date;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.honeyweb.gsoc.dao.OrganizationsDao;
import org.honeyweb.gsoc.model.Organizations;
import org.honeyweb.gsoc.model.Users;
import org.honeyweb.gsoc.pages.Profile;
import org.honeyweb.gsoc.services.OrganizationsManager;

public class OrganizationsManagerImpl implements OrganizationsManager{
	
	private final Log logger = LogFactory.getLog(OrganizationsManagerImpl.class);
	
    private OrganizationsDao organizationsDao = null;
    
	/**
     * setter to allows spring to inject organizationsDao implementation
     * @param organizationsDao : object (implementation of OrganizationsDao interface) to inject.
     */
    public void setOrganizationsDao(OrganizationsDao organizationsDao) {
		this.organizationsDao = organizationsDao;
	}
    
    /**
     * {@inheritDoc}
     */
    public Organizations getOrganization(Users user){
    	return organizationsDao.getOrganization(user);
    }
    
    /**
     * {@inheritDoc}
     */
    public Organizations getOrganizationByAdminId(int adminId){
    	return organizationsDao.getOrganizationByAdminId(adminId);
    }
    
    /**
     * {@inheritDoc}
     */
    public ArrayList<Organizations> getListOrganizations(){
    	return organizationsDao.getListOrganizations();
    }
   
    /**
     * {@inheritDoc}
     */
    public ArrayList<String> getListOrganizationsByName(){
    	
    	ArrayList<Organizations> listOrganizations = organizationsDao.getListOrganizations();
    	
		ArrayList<String> listOrganizationsString = new ArrayList<String>();
		for (Organizations o : listOrganizations ){
			listOrganizationsString.add(o.getName());
			logger.debug("organizations name:"+o.getName());
		}
		
		return listOrganizationsString;
		
    }
    
    /**
     * {@inheritDoc}
     */
    public ArrayList<Integer> getListOrganizationsById(){
    	
    	ArrayList<Organizations> listOrganizations = organizationsDao.getListOrganizations();
    	
		ArrayList<Integer> listOrganizationsId = new ArrayList<Integer>();
		for (Organizations o : listOrganizations ){
			listOrganizationsId.add(o.getId());
			logger.debug("organizations id:"+o.getId());
		}
		
		return listOrganizationsId;
		
    }
    
    /**
     * {@inheritDoc}
     */
    public void addOrganization(String name, int adminId) {
    	Date date = new Date();
        Organizations organization = new Organizations(name, adminId);
        logger.debug("organization name :"+ name);
        organizationsDao.addOrganization(organization);    
    }
    
    /**
     * {@inheritDoc}
     */
    public void addOrganizationsHoneypotsId(int organizationId, int honeypotsId){
    	organizationsDao.addOrganizationsHoneypotsId(organizationId,honeypotsId);
    }
    

    /**
     * {@inheritDoc}
     */
    public void delOrganizationsHoneypotsId(int organizationId, int honeypotsId){
    	organizationsDao.delOrganizationsHoneypotsId(organizationId,honeypotsId);
    }
    


}
